home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / util / notify.awk < prev    next >
Text File  |  1994-08-01  |  6KB  |  192 lines

  1. #! /bin/sh
  2. #    $Header: /usr/people/sam/fax/util/RCS/notify.awk,v 1.1 1994/04/06 18:31:43 sam Rel $
  3. #
  4. # FlexFAX Facsimile Software
  5. #
  6. # Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  7. # Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  8. # Permission to use, copy, modify, distribute, and sell this software and 
  9. # its documentation for any purpose is hereby granted without fee, provided
  10. # that (i) the above copyright notices and this permission notice appear in
  11. # all copies of the software and related documentation, and (ii) the names of
  12. # Sam Leffler and Silicon Graphics may not be used in any advertising or
  13. # publicity relating to the software without the specific, prior written
  14. # permission of Sam Leffler and Silicon Graphics.
  15. # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16. # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17. # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18. # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22. # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23. # OF THIS SOFTWARE.
  24. #
  25.  
  26. #
  27. # Awk support program for notify shell script.  This
  28. # stuff is broken out into a separate file to avoid
  29. # overflowing the exec arg list on some systems like SCO.
  30. #
  31.  
  32. #
  33. # Construct a return-to-sender message.
  34. #
  35. func returnToSender()
  36. {
  37.     printf "\n    ---- Unsent job status ----\n\n"
  38.     printf "%11s: %s\n", "Destination", number;
  39.     printf "%11s: %s\n", "Sender", sender;
  40.     printf "%11s: %s\n", "Mailaddr", mailaddr;
  41.     if (modem != "any")
  42.     printf "%11s: %s\n", "Modem", modem;
  43.     printf "%11s: %u (mm)\n", "PageWidth", pagewidth;
  44.     printf "%11s: %.0f (mm)\n", "PageLength", pagelength;
  45.     printf "%11s: %.0f (lpi)\n", "Resolution", resolution;
  46.     printf "%11s: %s\n", "Status", status;
  47.     printf "%11s: %u (consecutive failed calls to destination)\n",
  48.     "Dials", ndials;
  49.     printf "%11s: %u (attempts to send current page)\n",
  50.     "Attempts", ntries;
  51.     printf "%11s: %u (directory of next page to send)\n",
  52.     "Dirnum", dirnum;
  53.     if (nfiles > 0) {
  54.     printf "\n    ---- Unsent files submitted for transmission ----\n\n";
  55.     printf "This archive was created with %s, %s, and %s.\n",
  56.         tar, compressor, encoder;
  57.     printf "The original files can be recovered by applying the following commands:\n";
  58.     printf "\n";
  59.     printf "    %s            # generates rts.%s.Z file\n", decoder, tar;
  60.     printf "    %s rts.%s.Z  | %s xvf -    # generates separate files\n",
  61.         decompressor, tar, tar;
  62.     printf "\n";
  63.     printf "and the job can be resubmitted using the following command:\n";
  64.     printf "\n";
  65.     printf "    sendfax -d %s" poll notify resopt "%s\n", number, files;
  66.     printf "\n";
  67.  
  68.     system("cd docq;" tar " cf - " files \
  69.             " | " compressor \
  70.             " | " encoder " rts." tar ".Z");
  71.     }
  72. }
  73.  
  74. func returnTranscript(pid, canon)
  75. {
  76.     system(transcript " " pid " \"" canon "\" 2>&1");
  77. }
  78.  
  79. func printStatus(s)
  80. {
  81.     if (s == "")
  82.     print "<no reason recorded>";
  83.     else
  84.     print s
  85. }
  86.  
  87. BEGIN        { nfiles = 0; }
  88. /^number/    { number = $2; }
  89. /^sender/    { sender = $2; }
  90. /^mailaddr/    { mailaddr = $2; }
  91. /^jobtag/    { jobtag = $2; }
  92. /^status/    { status = $2; }
  93. /^resolution/    { resolution = $2;
  94.           if (resolution == 196)
  95.               resopt = " -m";
  96.         }
  97. /^npages/    { npages = $2; }
  98. /^dirnum/    { dirnum = $2; }
  99. /^ntries/    { ntries = $2; }
  100. /^ndials/    { ndials = $2; }
  101. /^pagewidth/    { pagewidth = $2; }
  102. /^pagelength/    { pagelength = $2; }
  103. /^modem/    { modem = $2; }
  104. /^notify/    { if ($2 == "when done")
  105.               notify = " -D";
  106.           else if ($2 == "when requeued")
  107.               notify = " -R";
  108.         }
  109. /^sstatus/    { jstatus = $2; }
  110. /^[!]*post/    { split($2, parts, "/");
  111.           if (!match(parts[2], "\.cover")) {    # skip cover pages
  112.              files = files " " parts[2];
  113.              nfiles++;
  114.           }
  115.         }
  116. /^!tiff/    { split($2, parts, "/"); files = files " " parts[2]; nfiles++; }
  117. /^poll/        { poll = " -p"; }
  118. END {
  119.     if (jobtag == "")
  120.     jobtag = FILENAME;
  121.     print "To: " mailaddr;
  122.     print "Subject: notice about facsimile job " jobtag;
  123.     print "";
  124.     printf "Your facsimile job \"" jobtag "\" to \"" number "\"";
  125.     if (why == "done") {
  126.     print " was completed successfully.";
  127.     printf "Total transmission time was " jobTime ".";
  128.     if (status != "")
  129.         print "  Additional information:\n    " status;
  130.     } else if (why == "failed") {
  131.     printf " failed because:\n    ";
  132.     printStatus(status);
  133.     returnTranscript(pid, canon);
  134.     returnToSender();
  135.     } else if (why == "requeued") {
  136.     printf " was not sent because:\n    ";
  137.     printStatus(status);
  138.     print "";
  139.     print "The job will be retried at " nextTry "."
  140.     returnTranscript(pid, canon);
  141.     } else if (why == "removed" || why == "killed") {
  142.     print " was deleted from the queue.";
  143.     if (why == "killed")
  144.         returnToSender();
  145.     } else if (why == "timedout") {
  146.     print " could not be sent after repeated attempts.";
  147.     returnToSender();
  148.     } else if (why == "format_failed") {
  149.     print " was not sent because"
  150.     print "conversion of PostScript to facsimile failed.";
  151.     print "The output from \"" ps2fax "\" was:\n";
  152.     print status "\n";
  153.     printf "Check your job for non-standard fonts %s.\n",
  154.         "and invalid PostScript constructs";
  155.     returnToSender();
  156.     } else if (why == "no_formatter") {
  157.     print " was not sent because";
  158.     print "the conversion program \"" ps2fax "\" was not found.";
  159.     returnToSender();
  160.     } else if (match(why, "poll_*")) {
  161.     printf ", a polling request,\ncould not be completed because ";
  162.     if (why == "poll_rejected")
  163.         print "the remote side rejected your request.";
  164.     else if (why == "poll_no_document")
  165.         print "no document was available for retrieval.";
  166.     else if (why == "poll_failed")
  167.         print "an unspecified problem occurred.";
  168.     print "";
  169.     printf "Total connect time was %s.\n", jobTime;
  170.     } else if (why == "file_rejected") {
  171.     printf " was rejected because:\n    ";
  172.     printStatus(status);
  173.     returnToSender();
  174.     } else {
  175.     print " had something happen to it."
  176.     print "Unfortunately, the notification script was invoked",
  177.         "with an unknown reason"
  178.     print "so the rest of this message is for debugging:\n";
  179.     print "why: " why;
  180.     print "jobTime: " jobTime;
  181.     print "pid: " pid;
  182.     print "canon: " canon;
  183.     print "nextTry: " nextTry;
  184.     print  "";
  185.     print "This should not happen, please report it to your administrator.";
  186.     returnToSender();
  187.     }
  188. }
  189.